package org.bwf.study.Interceptors;

import org.bwf.study.util.RedisUntil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class IdentityInter implements HandlerInterceptor {

    @Resource
    private RedisUntil redisUntil;

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj){

        // 这个拦截器主要是验证用户是否登录

        String token = request.getHeader("Authorization");

        if(token == null || "".equals(token)) return false;

        Object result = redisUntil.get(token);

        if(result == null) return false;

        return true;
    }
}
